package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IdleAffiliateMaterial;
import com.ruoyi.system.service.IIdleAffiliateMaterialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 闲鱼联盟物料Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/material")
public class IdleAffiliateMaterialController extends BaseController
{
    @Autowired
    private IIdleAffiliateMaterialService idleAffiliateMaterialService;

    /**
     * 查询闲鱼联盟物料列表
     */
    @Anonymous
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody IdleAffiliateMaterial idleAffiliateMaterial)
    {
        startPage();
        List<IdleAffiliateMaterial> list = idleAffiliateMaterialService.selectIdleAffiliateMaterialList(idleAffiliateMaterial);
        return getDataTable(list);
    }

    /**
     * 导出闲鱼联盟物料列表
     */
    @Anonymous
    @Log(title = "闲鱼联盟物料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IdleAffiliateMaterial idleAffiliateMaterial)
    {
        List<IdleAffiliateMaterial> list = idleAffiliateMaterialService.selectIdleAffiliateMaterialList(idleAffiliateMaterial);
        ExcelUtil<IdleAffiliateMaterial> util = new ExcelUtil<IdleAffiliateMaterial>(IdleAffiliateMaterial.class);
        util.exportExcel(response, list, "闲鱼联盟物料数据");
    }

    /**
     * 获取闲鱼联盟物料详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(idleAffiliateMaterialService.selectIdleAffiliateMaterialById(id));
    }

    /**
     * 新增闲鱼联盟物料
     */
    @Anonymous
    @Log(title = "闲鱼联盟物料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IdleAffiliateMaterial idleAffiliateMaterial)
    {
        return toAjax(idleAffiliateMaterialService.insertIdleAffiliateMaterial(idleAffiliateMaterial));
    }

    /**
     * 修改闲鱼联盟物料
     */
    @Anonymous
    @Log(title = "闲鱼联盟物料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IdleAffiliateMaterial idleAffiliateMaterial)
    {
        return toAjax(idleAffiliateMaterialService.updateIdleAffiliateMaterial(idleAffiliateMaterial));
    }

    /**
     * 删除闲鱼联盟物料
     */
    @Anonymous
    @Log(title = "闲鱼联盟物料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(idleAffiliateMaterialService.deleteIdleAffiliateMaterialByIds(ids));
    }

    /**
     * 根据商品ID查询闲鱼联盟物料
     */
    @Anonymous
    @GetMapping("/item/{itemId}")
    public AjaxResult getInfoByItemId(@PathVariable("itemId") String itemId)
    {
        return success(idleAffiliateMaterialService.selectIdleAffiliateMaterialByItemId(itemId));
    }

    /**
     * 修改物料上下线状态
     */
    @Anonymous
    @Log(title = "闲鱼联盟物料", businessType = BusinessType.UPDATE)
    @PutMapping("/online/{id}/{isOnline}")
    public AjaxResult updateOnlineStatus(@PathVariable("id") Long id, @PathVariable("isOnline") Boolean isOnline)
    {
        return toAjax(idleAffiliateMaterialService.updateOnlineStatus(id, isOnline));
    }
} 